package me.firstapp.config;

import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.FilterRegistration.Dynamic;

import org.springframework.web.filter.DelegatingFilterProxy;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

	@Override
	protected Class<?>[] getRootConfigClasses() {
		return new Class<?>[] { RootConfig.class };
	}

	@Override
	protected Class<?>[] getServletConfigClasses() {
		return new Class<?>[] { WebConfig.class };
	}

	@Override
	protected String[] getServletMappings() {
		return new String[] { "/", "*.html", "*.do" };
	}

	@Override
	protected void customizeRegistration(javax.servlet.ServletRegistration.Dynamic registration) {
		registration.setMultipartConfig(new MultipartConfigElement("/mnt/kamifile", 2097152, 4194304, 0));
	}

	@Override
	public void onStartup(ServletContext servletContext) throws ServletException {
		// 验签配置
		Dynamic apiSecuritySignFilter = servletContext.addFilter("openApiFilter", DelegatingFilterProxy.class);
		apiSecuritySignFilter.addMappingForUrlPatterns(null, false, "/openApi/*");
		super.onStartup(servletContext);
	}
}
